<template>
  <div>
    <danger-detail-info :form="form"></danger-detail-info>
  </div>
</template>

<script>
import { deepClone } from "@/utils";
import { Dialog } from "vant";
import DangerDetailInfo from "./dangerDetailInfo.vue";
export default {
  components: { DangerDetailInfo },
  data() {
    return {
      baseUrl: process.env.VUE_APP_BASE_API,
      id: this.$route.query.id,
      CTCode: this.$route.query.CTCode,
      border: false,
      reason: false,
      expenses: false,
      showCalendar: false,
      form: {},
      editForm: {},
      remarks: "",
      images: [],
      radio: "1",
      VerifyNotPassReason: "1",
      required:false,
    };
  },
  created() {
    this.geDetail();
  },
  methods: {
    // 打开日历
    openCalendar(idx) {
      this.idx = idx;
      this.showCalendar = true;
    },
    // 获取详情
    geDetail() {
      this.$axios
      .get("/OtherDangerCheckTaskDetailJG/GetYtsDetail",{params:{ id: this.id,CTCode:this.CTCode}})
      .then((res)=>{
        this.form = res.data;
        this.editForm = deepClone(res.data);
      })
    },
    onConfirm(date) {
      const dateTime = formatDate(date);
      this.editForm[this.idx] = getDate(dateTime);
      this.showCalendar = false;
    },
    submit() {
      if (this.radio == 1) {
        let param = {
          ID: this.editForm.ID,
          Remarks: this.editForm.Remarks,
          VerifyAttachs: this.editForm.VerifyAttachs,
        };
        Dialog.confirm({
          title: "询问",
          message: "隐患一旦验收通过后无法撤销，您确定验收通过吗？",
        })
          .then(() => {
            // on confirm
            this.$axios
            .post("/OtherDangerCheckTaskDetailJG/ConfirmVerify",param)
            .then((res)=>{
              this.$toast("保存成功");
              this.$router.goRefresh(-1);
            })
            .catch((err) => {
              console.log("err", err);
            });
          })
          .catch(() => {
            // on cancel
          });
      } else {
        if (!this.editForm.Remarks) {
          return this.$toast("请填写验收说明");
        }
        let param = {
          ID: this.editForm.ID,
          Remarks: this.editForm.Remarks,
          VerifyAttachs: this.editForm.VerifyAttachs,
          VerifyNotPassReason: this.VerifyNotPassReason,
        };

        this.$axios
        .post("/OtherDangerCheckTaskDetailJG/BackVerify",param)
        .then((res)=>{
          this.$toast("保存成功");
          this.$router.goRefresh(-1);
        })
        .catch((err) => {
          console.log("err", err);
        });
      }
    },
    handleChange(val){
      
      this.required = (val =="2")
    }
  },
};
</script>
